home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7868 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: charm.il.ft.hse.nl!not-for-mail
  2. From: robert@il.ft.hse.nl (robert)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: using pipe() and dup2??????
  5. Date: 29 Feb 1996 10:41:14 +0100
  6. Organization: LSD...melts in your mind, not in your hand
  7. Message-ID: <4h3sbq$n35@charm.il.ft.hse.nl>
  8. References: <4h21f7$osc@maltese.eag.unisysgsg.com>
  9. NNTP-Posting-Host: charm.il.ft.hse.nl
  10.  
  11. ssadra@maltese.eag.unisysgsg.com (Daniel R. Ascheman):
  12.  >I am writing a program that uses grep to search for a password
  13.  >to cross reference......I have only heard about pipe() being used
  14.  >to manipulate to output of grep to a char buf[256] in my code instead
  15.  >of out putting greps output to STDOUT i.e. a file in my dir.
  16.  
  17. You should try popen(), which works much easier:
  18.  
  19. FILE    *fp;
  20. ...
  21. if ((fp = popen("grep ....", "r") == NULL)
  22.     error();
  23. ...
  24.  
  25. After this, you can use fp with most file-stream functions (fread(), fgets(),
  26. fclose()). However, since a pipe only be one of read/write (hence the "r"),
  27. you can either read-only or write-only using fp.
  28.  
  29. Also, since popen() uses /bin/sh to execute the command, it will support
  30. things like tilde-expansion.
  31.  
  32. Perhaps you could take a look at the manpage if things aren't clear
  33. enough.
  34.  
  35.                                                                 robert 
  36.  
  37.